<script setup lang="ts">
  import { request } from '@/utils/http'
  import { getCodeApi } from '@/apis/user'
  import { useCounterStore } from '@/stores/counter'
  // 测试登录
  const login1 = async () => {
    const res = await request.post(
      '/login/password',
      {
        password: 'abc12345',
        mobile: '13230000001',
      },
      {
        custom: {
          loading: false,
        },
      }
    )
    console.log(111, res)
    uni.showToast({
      title: '登录成功',
      icon: 'success',
    })
  }
  const login2 = async () => {
    const res = await request.post('/login/password', {
      password: '',
      mobile: '',
    })
    console.log(222, res)
  }

  // --- 测试验证码接口的类型校验 ---
  const getCode = async () => {
    const res = await getCodeApi({
      mobile: '13230000001',
      type: 'login', // 有类型校验和代码提示
    })
    console.log('getCodeApi 测试用的验证码为', res.code)
  }

  // 获取 CounterStore
  const store = useCounterStore()
</script>

<template>
  <view>
    <image src="@/static/logo.png" mode="widthFix" />
    <text class="test-class">对齐</text>
    <text class="iconfont icon-location"></text>
    <text class="uniui-icon-symbol-tool-03"></text>
    <view>------ request整合测试 ------</view>
    <button @click="login1()">测试登录-成功</button>
    <button @click="login2()">测试登录-失败</button>
    <button type="primary" @click="getCode()">测试获取验证码</button>
    <view>------ pinia整合测试 ------</view>
    <view>store.totalCount: {{ store.totalCount }}</view>
    <view>store.doubleCount: {{ store.doubleCount }}</view>
    <button @click="store.addCount()">点击增加</button>
    <navigator url="/pages/login/index">去登录页</navigator>
    <navigator url="/subpkg_archive/form/index">去分包-添加患者</navigator>
    <navigator url="/subpkg_archive/list/index">去分包-患者列表</navigator>
  </view>
</template>

<style lang="scss">
  @import '@/uni.scss';
  .test-class {
    @include text-overflow(2);
  }
  .icon-location {
    font-size: 100rpx;
    color: red;
  }
  .uniui-icon-symbol-tool-03 {
    width: 100rpx;
    height: 100rpx;
  }
</style>
